Understanding Call Sequence and Scope

The Carbon Printing Manager enforces a sequence of steps in the printing loop, and defines a valid scope for each routine. This means that your application must call certain routines before calling others.

Routines used out of sequence will return an error result of kPMOutOfScope . In the following example, the PMDefaultPageFormat function is called before PMBegin , and would therefore return the kPMOutOfScope result code:

err = PMDefaultPageFormat( aPageFormatRef ); /* out of scope call */
PMBegin();

All calls to Carbon Printing Manager functions must be made inside a PMBegin / PMEnd block. Routines that operate on a specific page have the further requirement that they be called inside a PMBeginPage / PMEndPage block. Note that the PMPrintSettings and PMPageFormat objects are valid only within the PMBegin / PMEnd block in which they are allocated, as they are automatically disposed by the PMEnd function.

The following table shows the scope of the most commonly used printing functions.

Scope of Carbon Printing Manager functions
PMBegin
All accessor functions
PMNewPrintSettings
PMNewPageFormat
PMDisposePrintSettings
PMDisposePageFormat
PMDefaultPrintSettings
PMDefaultPageFormat
PMValidatePrintSettings
PMValidatePageFormat
PMPageSetUpDialog
PMPrintDialog
PMSetIdleProc
PMBeginDocument
PMBeginPage
PMGetGrafPtr
PMEndPage
PMEndDocument
PMEnd